package com.g17.virtualpetbackend.service;

import com.g17.virtualpetbackend.entity.Medicine;
import com.g17.virtualpetbackend.repo.MedicineRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MedicineService {
    @Autowired
    private MedicineRepository medicineRepository;

    public List<Medicine> findAllMedicine()
    {
        return medicineRepository.findAll();
    }

    public Medicine getMedicineById(Long id) {
        return medicineRepository.findMedicineById(id);
    }

    public Medicine findMedicineByName(String medicine){
        return medicineRepository.findByMedicine(medicine);
    }

    public Medicine createMedicine(String medicine, String price, String function){
        return medicineRepository.createMedicine(medicine, price, function);
    }

    public Medicine updateMedicine(Long id, String medicine, String price, String function){
        return medicineRepository.updateMedicine(id, medicine, price, function);
    }

    public Medicine deleteMedicine(Long id){
        return medicineRepository.deleteMedicineById(id);
    }

    public void assignMedicineToUser(String medicine, String username){
        medicineRepository.linkMedicineAndUser(medicine,username);
    }

    public List<Medicine> findAllMedicineSubscribedByUser(String username){
        return medicineRepository.findAllMedicineSubscribedByUser(username);
    }

    public void unassignMedicineToUser(String medicine, String username){
        medicineRepository.unlinkMedicineAndUser(medicine,username);
    }
}
